<template>
  <el-dialog
      :title="!dataForm.emrBlId ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
<el-form-item label="患者编号" prop="emrHzId">
  <el-input v-model="dataForm.emrHzId" placeholder="患者编号"></el-input>

</el-form-item>
<el-form-item label="创建时间" prop="emrBlCreate">
  <el-input v-model="dataForm.emrBlCreate" placeholder="创建时间"></el-input>

</el-form-item>
<el-form-item label="病历更新时间" prop="emrBlUpdate">
  <el-input v-model="dataForm.emrBlUpdate" placeholder="病历更新时间"></el-input>

</el-form-item>
<el-form-item label="总页数" prop="emrBlPage">
  <el-input v-model="dataForm.emrBlPage" placeholder="总页数"></el-input>

</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          emrBlId: 0,
          emrHzId: '',
          emrBlCreate: '',
          emrBlUpdate: '',
          emrBlPage: ''
        },
        dataRule: {
          emrHzId: [
            { required: true, message: '患者编号不能为空', trigger: 'blur' }
          ],
          emrBlCreate: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          emrBlUpdate: [
            { required: true, message: '病历更新时间不能为空', trigger: 'blur' }
          ],
          emrBlPage: [
            { required: true, message: '总页数不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.emrBlId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.emrBlId) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrblinfo/info/${this.dataForm.emrBlId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.emrHzId = data.emrBlInfo.emrHzId
                this.dataForm.emrBlCreate = data.emrBlInfo.emrBlCreate
                this.dataForm.emrBlUpdate = data.emrBlInfo.emrBlUpdate
                this.dataForm.emrBlPage = data.emrBlInfo.emrBlPage
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrblinfo/${!this.dataForm.emrBlId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'emrBlId': this.dataForm.emrBlId || undefined,
                'emrHzId': this.dataForm.emrHzId,
                'emrBlCreate': this.dataForm.emrBlCreate,
                'emrBlUpdate': this.dataForm.emrBlUpdate,
                'emrBlPage': this.dataForm.emrBlPage
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
